import sys
from PySide6 import QtGui
from PySide6.QtGui import  QApplication,QFileDialog
from PySide6.QtCore import  SIGNAL,QRect,QObject,SLOT
import ui_qt1
from PySide6.Qwt5.anynumpy import *
import PySide6.Qwt5 as Qwt
from PySide6 import Qt
class dlgqt1(QtGui.QDialog):
    ui=ui_qt1.Ui_qt1Class();
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui.setupUi(self)
        self.x = arange(0, 10.0, 10.0/27)
        self.y1 = sin(self.x)
        self.y2=2*cos(self.x)
        curve = Qwt.QwtPlotCurve()
        curve.setPen(Qt.QPen(Qt.Qt.darkGreen))
        #curve.setStyle(Qwt.QwtPlotCurve.Lines)
        curve.setCurveAttribute(Qwt.QwtPlotCurve.Fitted)
        curve.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Cross,
                                      Qt.QBrush(),
                                      Qt.QPen(Qt.Qt.black),
                                      Qt.QSize(5, 5)))
        curve.setData(self.x, self.y1)                                
        
        self.curve1=curve
        curve = Qwt.QwtPlotCurve()
        curve.setPen(Qt.QPen(Qt.Qt.red))
        #curve.setStyle(Qwt.QwtPlotCurve.Sticks)
        curve.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
                                      Qt.QBrush(Qt.Qt.yellow),
                                      Qt.QPen(Qt.Qt.blue),
                                      Qt.QSize(5, 5)))
        curve.setData(self.x, self.y2)                                                              
        self.curve2=curve
        # self.curve2.attach(self.ui.qwtPlot)
        # self.ui.qwtPlot.replot()

    def on_pushButton_cos_clicked(self):
        self.zoomer=None
        self.curve1.detach()
        self.curve2.attach(self.ui.qwtPlot)
        self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom,
                                        Qwt.QwtPlot.yLeft,
                                        Qwt.QwtPicker.DragSelection,
                                        Qwt.QwtPicker.AlwaysOff,
                                        self.ui.qwtPlot.canvas())
        print(self.zoomer.scaleRect())
        self.zoomer.setZoomBase(1)                                                                                
    def on_pushButton_sin_clicked(self):
        self.zoomer=None
        self.curve2.detach()
        self.curve1.attach(self.ui.qwtPlot)
        self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom,
                                        Qwt.QwtPlot.yLeft,
                                        Qwt.QwtPicker.DragSelection,
                                        Qwt.QwtPicker.AlwaysOff,
                                        self.ui.qwtPlot.canvas())
        print(self.zoomer.scaleRect())
        self.zoomer.setZoomBase(1)                                        
if __name__ == "__main__":
    a = QApplication(sys.argv)
    QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
    w =dlgqt1()
    w.show()
    sys.exit(a.exec_())